Skip to content

Conversation

@polina-c
Copy link
Collaborator

@polina-c polina-c commented Dec 24, 2025

Contributes to #607

  1. Remove ChatMessageRole: this library should not enforce the set of roles, as it can vary from case to case. The role should be part of envelope in client's code.
  2. Rename ChatMessage to Message, because this library can be used in chats and in other systems.
  3. Use constants for repeating literals
  4. Remove postfix 'Part' from part type literals, to reduce size of messages.
  5. Extend test coverage for primitives.
  6. Add test for example.
  7. Follow Gemini's advises below
  8. Replace dynamic with Object?
  9. Refactor Part to make the class extendable.
  10. Update equality to match Flutter codestyle and to use package collection for deep collection comparison

gemini-code-assist[bot]

This comment was marked as outdated.

@polina-c polina-c changed the title - Some cleanups to make the library useable for wide range of use cases. Dec 24, 2025
@polina-c polina-c changed the title Some cleanups to make the library useable for wide range of use cases. Updates to make the library applicable for wide range of use cases. Dec 24, 2025
@polina-c polina-c changed the title Updates to make the library applicable for wide range of use cases. Updates to make the library applicable for wider range of use cases. Dec 24, 2025
gemini-code-assist[bot]

This comment was marked as outdated.

@polina-c
Copy link
Collaborator Author

/gemini review

@polina-c polina-c marked this pull request as ready for review December 24, 2025 06:08
@polina-c
Copy link
Collaborator Author

polina-c commented Dec 24, 2025

@csells , how does it look?

@polina-c polina-c changed the title Updates to make the library applicable for wider range of use cases. Updates to make the library applicable for wider range of use cases, and more stable. Dec 24, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces several significant and beneficial changes to make the library more flexible and robust. Key changes include removing the enforced ChatMessageRole, renaming ChatMessage to Message, and using constants for JSON keys to reduce message size. The test coverage has been significantly improved, including a new test for the example, which is excellent. My review focuses on some opportunities to improve code clarity and leverage more modern Dart features, such as using const constructors for immutable classes and refactoring switch statements/expressions for better readability. Overall, this is a solid pull request that improves the library's design and usability.

@polina-c polina-c requested review from csells and yjbanov January 9, 2026 04:20
/// If there are many parts of type [TextPart], the [text] property
/// will be a concatenation of all of them.
/// Many text parts is convenient to have to support
/// streaming of the message.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "streaming of the message" mean? Standard Dart Streams are asynchronous constructs, but parts are provided as one synchronous List.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When LLM sends message, it adds parts one by one and, as result, text is split. Stream is not needed here, because the message is created when full message is received. I removed this comment, because, yes, it causes questions.

description:
name: characters
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you need to update pubspec.lock to make your code changes to work? Or was this by accident?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not mean, but it is unavoidable side effect of storing pubspec.lock in git - sometimes it changes.

@yjbanov
Copy link
Collaborator

yjbanov commented Jan 9, 2026

@csells @polina-c

My 2c on the ChatMessage => Message renaming. In the genUI context some messages coming from the LLM are UI updates/mutations to an existing genUI surface. It would be counterintuitive to think of such messages as "chat messages". So I think the renaming is the right choice. An application that uses this library for a chat application could wrap the Message object into a ChatMessage object that would contain additional chat-specific semantics. I can even imagine a "chat message" being one of or a composition of a text message, genui surface, and a data message (e.g. containing a generated image).

@polina-c
Copy link
Collaborator Author

polina-c commented Jan 14, 2026

@csells , @yjbanov

We discussed the subject on the doc and agreed:

  1. Fixed set of roles will make the class ChatMessage robust and well-reusable between packages.
  2. The name Message will stay reserved for the case when we see that class ChatMessage does not fit some stories.
  3. The class Parts will make it possible to use parts independently.

See details in go/message-in-ai-primitives

Will update the PR shortly.

@polina-c polina-c requested a review from yjbanov January 15, 2026 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants